/**
 * Created with  SublimeText
 * @Author:      Lyle
 * @DateTime:    2017-11-5 17:44:25
 * @Description: 
 */

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'

Vue.use(Router)

const router = new Router({
    mode: 'history',
    base: __dirname,
})

router.beforeEach((to, from, next) => {
    console.log('beforeEach');
    next();
})

router.afterEach((route) => {
    console.log('afterEach');
})

router.onError((callback) => {
    console.log('onError');
})

router.pathPrefixes = () => {
    let str = '',
        path = window.location.pathname;
    if (path.indexOf('/mobile') == 0) {
        str = '/mobile'
    }
    return str;
}

let pathPrefixes = router.pathPrefixes();

let routes = [{
    path: pathPrefixes + '/',
    name: 'Home',
    component: Home
}]

router.addRoutes(routes);

export default router;
